<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<h3 class="sub-header">文章管理</h3>
			<button class="btn btn-primary" data-toggle="modal" data-target="#addArticleDiv">添加</button>
				<div class="table-responsive">
					<table class="table">
						<thead>
							<tr>
								<th>编号</th>
								<th>文章标题</th>
								<th>内容</th>
								<th>发布时间</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${articlePage.list }" var="article" varStatus="v">
								<tr class="active">
									<td>${v.count }</td>
									<td>${article.title }</td>
									<td> ${fn:substring(article.content, 0, 20) }</td>
									<td>${article.createTime }</td>
									<td>
										<button type="button"
											class="btn btn-default btn-xs  btn-warning" onclick="getArticle(${article.id})" >修改</button> 
											<a href="${ctx }/blog/deleteArticle?id=${article.id}" class="btn btn-default btn-xs  btn-danger">删除</a>
									</td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					</div>
					<ul class="pagination">
						<li><a
							href="<%=request.getContextPath() %>/blog/list.action?pageNo=${blogs.pre}">&laquo;</a></li>
						<li class="active"><a
							href="<%=request.getContextPath()%>/blog/list.action?pageNo=1">1</a></li>
						<li><a
							href="<%=request.getContextPath()%>/blog/list.action?pageNo=2">2</a></li>
						<li><a
							href="<%=request.getContextPath()%>/blog/list.action?pageNo=3">3</a></li>
						<li><a
							href="<%=request.getContextPath()%>/blog/list.action?pageNo=4">4</a></li>
						<li><a
							href="<%=request.getContextPath()%>/blog/list.action?pageNo=5">5</a></li>
						<li><a
							href="<%=request.getContextPath() %>/blog/list.action?pageNo=${blogs.next}">&raquo;</a></li>
					</ul>

	    <div class="modal fade" id="addArticleDiv" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		  <div class="modal-dialog">
		    <div class="modal-content">
		      <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
		        <h4 class="modal-title" id="myModalLabel">新增文章</h4>
		      </div>
		      <div class="modal-body">
				<form class="form-horizontal" role="form" action="<%=request.getContextPath() %>/blog/addArticle" method="post">
				<input type="hidden" name="userId" value="${user.id }"/>
				  <div class="form-group">
				    <label for="title" class="col-sm-2 control-label">title</label>
				    <div class="col-sm-10">
				      <input type="text" class="form-control" name="title">
				    </div>
				  </div>
				  <div class="form-group">
				    <label for="content" class="col-sm-2 control-label">content</label>
				    <div class="col-sm-10">
				      <textarea name="content" class="form-control" placeholder="文章内容" required></textarea>
				    </div>
				  </div>
				  <div class="form-group">
				    <label for="categoryId" class="col-sm-2 control-label">category</label>
				    <div class="col-sm-10">
				      <select  class="form-control" name="categoryId">
						  <option value="1">回忆</option>
						  <option value="2">麻买皮</option>
						</select>
				    </div>
				  </div>
				  <div class="form-group">
				    <div class="col-sm-offset-2 col-sm-10">
				      <button type="submit" class="btn btn-primary">新增</button>
				    </div>
				  </div>
				</form>
		      </div>
		    </div>
		  </div>
		</div>
	<div class="modal fade" id="updateArticleDiv" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content loginbox">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">
						<span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
					</button>
					<h4 class="modal-title">修改</h4>
				</div>
				<form class="form-signin" role="form" action="<%=request.getContextPath() %>/blog/updateArticle" method="post">
				<input type="hidden" name="categoryId" id="categoryId">
				<input type="hidden" name="id" id="id">
				<input type="hidden" name="userId" value="${user.id }">
		文章标题： <input id="title" name="title" class="form-control" placeholder="文章标题"required autofocus> 
		文章内容:<textarea id="content" name="content" class="form-control" placeholder="文章内容" required></textarea>
					<input class="btn btn-lg btn-primary btn-block" type="submit" value="修改" ></input>
				</form>
			</div>
		</div>
	</div>
	<script>
 function getArticle(id){
		$.post("<%=request.getContextPath() %>/blog/getSingleArticle?id="+id,function(data){
			$("#title").val(data.title);
			$("#content").html(data.content);
			$("#id").val(data.id);
			$("#categoryId").val(data.categoryId);
		},'json');
		 $('#updateArticleDiv').modal('show');  
	};
	
	
	</script>
				